﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.DAL;
using Gift.Model;
using System.Data;
using System.Text;

namespace WebSite.cn
{
    public partial class partner :  BasePage
    {
        readonly DALBrand theBrand = new DALBrand();
        public StringBuilder sBrandHtml = new StringBuilder();
        public StringBuilder sBrandPicHtml = new StringBuilder();
        readonly DALCompanyPartner theCompanyPartner = new DALCompanyPartner();
        tbCompanyPartner oCompanyPartner;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                this.BindBrand();
            }
        }


        void BindBrand()
        {
            DataTable table = theBrand.GetList(" isnull(visible,0)=1 and brandName !='其它' order by brandOrder ").Tables[0];

            foreach (DataRow dr in table.Rows)
            {
                if (dr["brandLogo"].ToString() != "")
                {
                    sBrandHtml.AppendFormat("<A href=\"{0}\">{1}</A><EM>|</EM>"
                                              , dr["brandUrl"]
                                              , dr["brandName"]
                                              );
                    sBrandPicHtml.AppendFormat("<li><a href=\"{0}\" target=\"{3}\" title=\"{1}\"> <img  src=\"{2}\" onmouseover=\"this.className='htmer_img'\" onmouseout=\"this.className='htmer_img_none'\"  /></a><p>{1}</p></li>"
                                               , string.IsNullOrEmpty(dr["brandUrl"].ToString()) ? "#" : dr["brandUrl"].ToString()
                                               , dr["brandName"]
                                               , "/uploadfile/product/" + dr["brandLogo"]
                                                , string.IsNullOrEmpty(dr["brandUrl"].ToString()) ? "_self" : "_blank"
                                               );

                    if (sBrandHtml.Length > 10)
                    {
                        sBrandHtml.Remove(sBrandHtml.Length - 10, 10);
                    }
                }
               
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            oCompanyPartner = new tbCompanyPartner();
            oCompanyPartner.companyName = this.txtCompanyName.Text.Trim();
            oCompanyPartner.isCertificate = this.rblCertificate.SelectedItem.Value == "1" ? true : false;
            oCompanyPartner.linker = this.txtLinker.Text.Trim();
            oCompanyPartner.linkWay = this.txtLinkTel.Text.Trim();
            oCompanyPartner.companyAddress = this.txtAddress.Text.Trim();
            oCompanyPartner.remark = this.txtContent.Text.Trim();
            oCompanyPartner.suggeust = this.txtSuggest.Text.Trim();
            oCompanyPartner.email = this.txtEmail.Text.Trim();
            oCompanyPartner.goodsType = this.txtGoodsType.Text.Trim();
            theCompanyPartner.Add(oCompanyPartner);

            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.ClientScript.GetType(), "msg", "<script>alert('提交成功！');window.location.href='partner.aspx';</script>");

        }

        protected void ibtnReset_Click(object sender, ImageClickEventArgs e)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.ClientScript.GetType(), "reset", "<script>window.location.href='partner.aspx';</script>");
        }

    }
}